#include <iostream>
#include <vector>
#include "test.h"
#include "struct_ul.h"
#include "pw_import_store.h"
#include "password.h"
using namespace std;
int main() {
   /* *1.检测用户*/
    //将原始的id_密码转换为key_value，然后写到txt文件当中
    vector<pair<string,string>> s{{"22334","dhafhfh477395"},
                                 {"22356","47338fhhjf"},
                                 {"34567","8hrh8j30d"},
                                 {"34775","7fw#!fhhf"},
                                 {"43324","r83hfhwe"}};
    auto t = id_password_to_key_value(s);
    int size = key_value_to_txt(t,"../user_kv.txt");

    /**将txt中的内容存到dat文件中*/
    txt_to_dat("../user_kv.txt","../user_kv.dat",size);

    /**系统启动hashtable读取dat文件*/
    Import_User_Hash_table("../user_kv.dat");

    /**读取hashtable里的信息来看导入是否正确*/
    for(int i = 1;i <= user_password_id.size;i++)
        cout<<user_password_id.data[i].key<<" "<<user_password_id.data[i].value<<endl;
    /**认证*/
    cout<<User_Authentication("22334","dhafhfh477395")<<endl;//1
    cout<<User_Authentication("22334","dhafhfh77395")<<endl;//0
    cout<<User_Authentication("95838","fhewfaj8384")<<endl;//0
    /**注册*/
    cout<<User_Register("95838","fhewfaj8384")<<endl;//1
    /**再认证*/
    cout<<User_Authentication("95838","fhewfaj8384")<<endl;//1
    /**密码修改*/
    cout<<User_Password_Modify("95838","fhewfaj838")<<endl;//1
    /**原密码认证*/
    cout<<User_Authentication("95838","fhewfaj8384")<<endl;//0
    /**新密码认证*/
    cout<<User_Authentication("95838","fhewfaj838")<<endl;//1
    /**再次输出hash里的key,value*/
    for(int i = 1;i <= user_password_id.size;i++)
        cout<<user_password_id.data[i].key<<" "<<user_password_id.data[i].value<<endl;
   /**将hash保存到dat文件当中*/
    Store_User_Hash_table("../user_kv.dat");
    /**将dat文件再保存到txt文件当中，方便观察*/
    dat_to_txt("../user_kv.dat","../user_kv.txt");
    system("pause");


   /**用户管理员和图书管理员数量不会太多，其次应该不会用到注册这个功能
    2.检测用户管理员*/
    vector<pair<string,string>> s2{{"11111","dhafdajfjajfhah"}};
    auto t2 = id_password_to_key_value(s2);
    size = key_value_to_txt(t2,"../user_kv.txt");/**为了方便，三类人员的数据存到一个txt文件当中*/

    txt_to_dat("../user_kv.txt","../user_manager_kv.dat",size);
    Import_User_Manager_Hash_table("../user_manager_kv.dat");
    for(int i = 1;i <= user_manager_password.size;i++)
        cout<<user_manager_password.data[i].key<<" "<<user_manager_password.data[i].value<<endl;

    /**认证*/
    cout<<User_Manager_Authentication("11111","dhafdajfjajfhah")<<endl;//1
    cout<<User_Manager_Authentication("1111","dhafdajfjajfhah")<<endl;//0
    /**密码修改*/
    cout<<User_Manager_Password_Modify("11111","dhafdajfjajfha")<<endl;//1
    /**原密码认证*/
    cout<<User_Manager_Authentication("11111","dhafdajfjajfhah")<<endl;//0
    /**新密码认证*/
    cout<<User_Manager_Authentication("11111","dhafdajfjajfha")<<endl;//1
    for(int i = 1;i <= user_manager_password.size;i++)
        cout<<user_manager_password.data[i].key<<" "<<user_manager_password.data[i].value<<endl;

    /**保存*/
    Store_User_Manager_Hash_table("../user_manager_kv.dat");
    dat_to_txt("../user_manager_kv.dat","../user_kv.txt");
    system("pause");


    /**3.检测图书管理员*/
    vector<pair<string,string>> s3{{"88888","hafjfjjfjfa"}};
    auto t3 = id_password_to_key_value(s3);
    size = key_value_to_txt(t3,"../user_kv.txt");/**为了方便，三类人员的数据存到一个txt文件当中*/

    txt_to_dat("../user_kv.txt","../script_manager_kv.dat",size);
    Import_Script_Manager_Hash_table("../script_manager_kv.dat");
    for(int i = 1;i <= script_manager_password.size;i++)
        cout<<script_manager_password.data[i].key<<" "<<script_manager_password.data[i].value<<endl;

    /**认证*/
    cout<<Script_Manager_Authentication("88888","hafjfjjfjfa")<<endl;//1
    cout<<Script_Manager_Authentication("8888","hafjfjjfjfa")<<endl;//0
    /**密码修改*/
    cout<<Script_Manager_Password_Modify("88888","hafjfjjfjf")<<endl;//1
    /**原密码认证*/
    cout<<Script_Manager_Authentication("88888","hafjfjjfjfa")<<endl;//0
    /**新密码认证*/
    cout<<Script_Manager_Authentication("88888","hafjfjjfjf")<<endl;//1
    for(int i = 1;i <= script_manager_password.size;i++)
        cout<<script_manager_password.data[i].key<<" "<<script_manager_password.data[i].value<<endl;

    /**保存*/
    Store_Script_Manager_Hash_table("../script_manager_kv.dat");
    dat_to_txt("../script_manager_kv.dat","../user_kv.txt");





}
